package com.jiugang.cardump.controller;


import com.jiugang.cardump.bean.InformationBean;
import com.jiugang.cardump.constant.StatusCodeConstant;
import com.jiugang.cardump.exception.SystemExceptionV110;
import com.jiugang.cardump.result.ResultInfoV110;
import com.jiugang.cardump.service.AlertService;
import lombok.extern.slf4j.Slf4j;
import org.apache.catalina.servlet4preview.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;
import java.time.LocalDateTime;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wuweinan
 * @since 2021-08-19
 */
@RestController
@RequestMapping("/alert")
@Slf4j
public class AlertController {

    @Autowired
    private AlertService alertService;   //报警信息业务实现类

    /**
     * @param id 设备Id
     * @return ResultInfoV110
     * @Description 根据设备Id查询报警状态接口
     */
    @GetMapping("/list")
    public ResultInfoV110 queryEquipmentAlertList(String id){
        log.info("AlertController的queryEquipmentAlertList的方法进入,参数id为"+id);

        //参数校验
        if(id == null){
            throw new SystemExceptionV110(InformationBean.setInformationBean(StatusCodeConstant.F002,"报警信息"));
        }
        return  alertService.selectEquipmentAlertList(id);
    }

    /**
     * @Author luoxin
     * @Description 报警信息查询接口
     * @Date 11:14 上午 2021/8/23
     * @param id，page，size，StartTime，endTime
     * @return
     */
    @GetMapping("/alllist")
    public ResultInfoV110 queryEquipmentAlertAllList(String id, Integer page, Integer size, String StartTime, String endTime){
        log.info("AlertServiceImpl的selectEquipmentAlertList的方法进入,参数equipmentId为" + id+",page="+page+",size"+size);

        //参数校验
        if(id == null){
            throw new SystemExceptionV110(InformationBean.setInformationBean(StatusCodeConstant.F002,"报警查询信息"));
        }
        return  alertService.selectEquipmentAlerAlltList(id,page,size,StartTime,endTime);
    }


    /**
     * @param equipmentId 设备编号
       @Descrption   统计过去一小时内的报警,将过去一小时分成12个等分区间
     */
    @GetMapping("/statistics")
    public ResultInfoV110 statisticsAlertInOneHour(String equipmentId){
        log.info("AlertController的statisticsAlertInOneHour方法进入,参数");
        if(equipmentId == null){
            throw new SystemExceptionV110(InformationBean.setInformationBean(StatusCodeConstant.F002,"报警统计"));
        }
        return  alertService.staticticsAlertInOneHour(equipmentId);
    }
}

